﻿<UserControl x:Class="WTwitter.View.TimelineContentsView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:vm="clr-namespace:WTwitter.ViewModel"
	xmlns:view="clr-namespace:WTwitter.View"
	xmlns:util="clr-namespace:WTwitter.ViewModel.Utility">
	<UserControl.Resources>
		
		<!--アイコン付きボタンのテンプレート-->
		<DataTemplate DataType="{x:Type util:ImageButton}">
			<Button Command="{Binding Path=Command}" ToolTip="{Binding Path=Description}"
					Background="Transparent" BorderBrush="Transparent" Style="{DynamicResource ImageButtonStyle}">
				<Image Source="{Binding Path=Image}" Width="16" Height="16"/>
			</Button>
		</DataTemplate>

		<DataTemplate DataType="{x:Type util:ToggleImageButton}">
			<Button Command="{Binding Path=Command}" ToolTip="{Binding Path=Description}"
					Background="Transparent" BorderBrush="Transparent" Style="{DynamicResource ImageButtonStyle}">
				<Image Width="16" Height="16">
					<Image.Style>
						<Style TargetType="{x:Type Image}">
							<Setter Property="Source" Value="{Binding Path=Image}"/>
							<Style.Triggers>
								<DataTrigger Binding="{Binding Path=IsOn}" Value="False">
									<Setter Property="Source" Value="{Binding Path=AlternativeImage}"/>
								</DataTrigger>
							</Style.Triggers>
						</Style>
					</Image.Style>
				</Image>
			</Button>
		</DataTemplate>

		<!--発言のテンプレート-->
		<DataTemplate x:Key="TimelineItemDataTemplate">
			<DockPanel Name="_Container">
				<!--右クリックメニュー-->
				<DockPanel.ContextMenu>
					<ContextMenu>
						<MenuItem Header="ブラウザで開く(_B)" Command="{x:Static util:CommonCommands.OpenByBrowser}" CommandParameter="{Binding Path=UserUrl}" />
						<MenuItem Header="フィルタ(_F)">
							<MenuItem Header="このユーザーをNGに登録(_N)" Command="{Binding Path=SetNgUserCommand}"/>
						</MenuItem>
					</ContextMenu>
				</DockPanel.ContextMenu>
				<!--アイコン-->
				<Image Source="{Binding Path=ProfileImageUrl}" Width="32" Opacity="0.8"
					   DockPanel.Dock="Left" VerticalAlignment="Top" Margin="5" ToolTip="{Binding Path=DetailDescription}">
				</Image>
				<DockPanel DockPanel.Dock="Top">
					<!--名前-->
					<TextBlock DockPanel.Dock="Left">
						<Hyperlink Command="{Binding Path=ShowUsersAllItemCommand}" 
								   TextDecorations=""
								   Style="{DynamicResource DesignedUserNameHyperlinkStyle}">
							<TextBlock Text="{Binding Path=Name}"/>
						</Hyperlink>
						<TextBlock.ToolTip>
							<ToolTip>
								<view:UserInfoView DataContext="{Binding Path=User}"/>
							</ToolTip>
						</TextBlock.ToolTip>
					</TextBlock>
					<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
						<!--ボタン-->
						<ItemsControl Name="_commands" ItemsSource="{Binding Path=Commands}">
							<ItemsControl.ItemsPanel>
								<ItemsPanelTemplate>
									<StackPanel Orientation="Horizontal" IsItemsHost="True"/>
								</ItemsPanelTemplate>
							</ItemsControl.ItemsPanel>
							<ItemsControl.Style>
								<Style TargetType="{x:Type ItemsControl}">
									<Style.Triggers>
										<DataTrigger Binding="{Binding ElementName=ItemContainer, Path=IsMouseOver}" Value="False">
											<Setter Property="Visibility" Value="Hidden"/>
										</DataTrigger>
									</Style.Triggers>
								</Style>
							</ItemsControl.Style>
						</ItemsControl>
						<!--時刻-->
						<TextBlock Text="{Binding Path=RelativeTimeString}" Foreground="White"/>
					</StackPanel>
				</DockPanel>
				<!--本文-->
				<view:TextComponentsView DataContext="{Binding Path=TextComponents}"/>
			</DockPanel>
		</DataTemplate>

		<!--発言を囲むListBoxIttemのテンプレート-->
		<Style TargetType="{x:Type ListBoxItem}" x:Key="{x:Type ListBoxItem}">
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type ListBoxItem}">
						<!--アイテムの枠-->
						<Border BorderBrush="{DynamicResource ContentsBackgroundBrush}" BorderThickness="2" Background="{DynamicResource ContentsBackgroundBrush}"
								CornerRadius="3" Margin="3" Padding="2"
								x:Name="ItemContainer">
							<ContentPresenter ContentTemplate="{StaticResource TimelineItemDataTemplate}"/>
						</Border>
						<ControlTemplate.Triggers>
							<!--選択アイテムのエフェクト-->
							<Trigger Property="IsSelected" Value="True">
								<Setter TargetName="ItemContainer" Property="Background" Value="{DynamicResource SelectedContentBackgroundBrush}"/>
								<Setter TargetName="ItemContainer" Property="BorderBrush" Value="{DynamicResource SelectedContentBackgroundBrush}"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>

	</UserControl.Resources>
	
	<ListBox x:Name="_timeline" ItemsSource="{Binding Path=ViewSource.View}"
			 ScrollViewer.HorizontalScrollBarVisibility="Disabled"	 HorizontalContentAlignment="Stretch"
			 ScrollViewer.CanContentScroll="False" Style="{DynamicResource DesignedListBoxStyle}">
		<ListBox.Resources>
			<Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
				<Setter Property="Opacity" Value="0.5"/>
			</Style>
		</ListBox.Resources>
	</ListBox>
</UserControl>
